/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eng.scc.core.schema.fetcher;

import com.eng.scc.core.data.Login;
import com.eng.scc.core.db.Database;
import com.eng.scc.core.db.Fetcher;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Rafael
 */
public class LoginFetcher implements Fetcher<Login>
{
    @Override
    public Login fetch( ResultSet ps ) throws Exception
    {
        Login l = new Login();
        
        l.setId( ps.getInt( 1 ) );
//        l.setPeople( ps.getInt( 2 ) );
        l.setUser( ps.getString( 3 ) );
        l.setPwd( ps.getString( 4 ) );
        l.setCreation( ps.getDate( 5 ) );
        l.setProfileAccess( ps.getShort( 6 ) );
        
        return l;
    }

    @Override
    public void insert( Login value, PreparedStatement ps ) throws Exception
    {
        value.setId( Database.getInstance().nextID( "core_logins" ) );
        
        ps.setInt( 1, value.getId() );
        ps.setInt( 2, value.getPeople().getId() );
        ps.setString( 3, value.getUser() );
        ps.setString( 4, value.getPwd() );
        ps.setDate( 5, value.getCreation() );
        ps.setShort( 6, value.getProfileAccess() );
    }

    @Override
    public void update( Login value, PreparedStatement ps ) throws Exception
    {
        ps.setInt( 1, value.getPeople().getId() );
        ps.setString( 2, value.getUser() );
        ps.setString( 3, value.getPwd() );
        ps.setDate( 4, value.getCreation() );
        ps.setShort( 5, value.getProfileAccess() );
        ps.setInt( 6, value.getId() );
    }
    
}
